package fr.grassaud.hmvc.vaadin.home;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;

import fr.grassaud.hmvc.component.View;
import fr.grassaud.hmvc.session.HMVCSession;
import fr.grassaud.hmvc.session.SessionContext;

@View(controlledBy = HomeController.class)
public class HomeView extends CustomComponent {

    private Panel panel;
    private Label label;
    private Button button;
    @SessionContext 
    private HMVCSession session;

    public HomeView() {
	panel = new Panel();
	setCompositionRoot(panel);

	label = new Label();

	button = new Button("OK");
	button.addListener(new ClickListener() {

	    @Override
	    public void buttonClick(ClickEvent event) {
		session.sendViewEvent(HomeView.this, new ChangeLabelEvent(HomeView.this));
	    }
	});

	panel.addComponent(label);
	panel.addComponent(button);

    }

    public void setLabel(String label) {
	this.label.setValue(label);
    }
}
